package cc.aiee.core.enums;

import lombok.Getter;
import lombok.Setter;

/**
 * <h6>错误编码信息</h6>
 * <p>
 * ERROR:
 * </p>
 * <ul>
 * <li>最高: -603</li>
 * </ul>
 * <p>
 * SUCCESS
 * </p>
 * <ol>
 * <li>最高: 800</li>
 * </ol>
 * 
 * @author YangLong<br>
 *         2020-10-15 17:34:06
 */
public enum ErrCodeEnum {
	/**
	 * ALL SUCCESS
	 */
	s_success_0("0", "成功"), s_refund_800("800", "退款成功"), s_cancel_801("801", "取消成功"),
	/**
	 * ALL ERROR
	 */
	e_fail_1("-1", "失败"), e_param_valid_400("-400", "参数校验失败", "1"), e_refunded_600("-600", "已退款"),
	e_cancel_601("-601", "取消失败"), e_refund_602("-602", "退款失败"), e_payment_603("-603", "支付失败");

	@Getter
	@Setter
	private String code;

	@Getter
	@Setter
	private String msg;

	@Getter
	@Setter
	/**
	 * 状态
	 * <li>0: 成功</li>
	 * <li>1: 失败</li>
	 * <li>null: 不知</li>
	 * <li>other: 中间状态</li>
	 */
	private String status;

	private ErrCodeEnum(String code, String msg) {
		this.code = code;
		this.msg = msg;
	}

	private ErrCodeEnum(String code, String msg, String status) {
		this.code = code;
		this.msg = msg;
		this.status = status;
	}

	public Boolean ok() {
		if (this.status == null) {
			return null;
		}
		boolean success = this.status.equals("0");
		// 是否处于中间状态
		boolean betweenness = (success || this.status.equals("1"));
		if (!betweenness) {
			return null;
		}
		return success == true;
	}
}
